/*
 * GeoVISTA Center (Penn State, Dept. of Geography)
 * Copyright (c), 2003-2011,  Jin Chen and Alan M. MacEachren, GeoVISTA Center, Penn State University
 * Licensed under Simplified BSD License
 *
 *
 * @author: jin Chen 
 * @date: Dec 15, 2005$
 * @version: 1.0
 */
package edu.psu.geovista.app.gmatrix.toolkit;

import javax.swing.*;
import java.awt.*;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class MatrixUtils {
    /**
     *
     * @param comp
     * @param actmap   key: the menu name, values: A list of actions for the menu
     * @param x
     * @param y
     */
    public  static void showPopup( JComponent comp, Map actmap,int x, int y){



        final JPopupMenu popup=new JPopupMenu();
        class Util{
           private void setpopup(JPopupMenu popup,String name, List acts){
               JMenu main = new JMenu(name);
               popup.add(main);
               popup.add(main);
           for (Iterator iterator = acts.iterator(); iterator.hasNext();) {
               Action action = (Action) iterator.next();
               JMenuItem mt=new JMenuItem(action);
               main.add(mt);
           }//for
           }
         }
         Util util=new Util();
        Set keys = actmap.keySet();
        for (Iterator iterator = keys.iterator(); iterator.hasNext();) {
            String key = (String) iterator.next();
            List acts = (List) actmap.get(key);
             util.setpopup(popup,key,acts);

        }

         popup.show(comp,x,y);
        }//method
     //todo move to generic class
     public static void print(Set<Point> points, String headspace){
         for (Iterator iterator = points.iterator(); iterator.hasNext();) {
             Point point = (Point) iterator.next();
             print(point,headspace);
         }
     }
    public static void print(Point p,String headspace){
        System.out.println(headspace+ "["+p.x+","+p.y+"]");


    }
    public  static void print(int[] array, String headspace){
        System.out.print(headspace+" ");
        for (int i=0;i<array.length ;i++){
            System.out.print(array[i]+",");
        }
        System.out.println("");
    }
}
